package ioStream.file.processStream.characterStream;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * Created with IntelliJ IDEA
 * Description:缓冲字符输出流学习
 * User:22954
 * Date:2024-03-17
 * Time:19:07
 */
@SuppressWarnings("all")
public class BufferedWriter_ {
    /*
    class BufferedWriter extends Writer 缓冲字符输出流继承输出流
    ============================================================
    private Writer out
    BufferedWriter(Writer out)  包装节点流中的输出流
    ============================================================
    close()->implClose()->flushBuffer()->implFlushBuffer()->write()
        write()只将数据写入流中,在调close()/flush()时,底层调用Writer的write()方法才真正将数据写入文件中
     */
    public static void main(String[] args) {
        String filePath = "f:/Test/hello_world.txt";
        BufferedWriter bufferedWriter = null;
        try {
            bufferedWriter = new BufferedWriter(new FileWriter(filePath,true));
            bufferedWriter.write("hello world");
            bufferedWriter.newLine();
            bufferedWriter.write("Hello world");
            bufferedWriter.newLine();
            bufferedWriter.write("hello World");
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
